﻿//------------------------------------------------------------------------------
// System Name:    Customer Service Platform
// Component:      CIS  Domestic ClusterManagement
// Created By:     Samara Jiang (samaraj@wicresoft.com)
// Created Date:   2011-1-30
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASB.CC.Business.CIS;
using ASBCC.Business;
using ASBCC.Business.CIS;
using ASBCC.Database.EntityFramework;

namespace BEGDC.CC.Web.CIS2.Domestic.Admin
{
    /// <summary>
    ///  CIS  Domestic ClusterManagement
    /// </summary>
    public partial class ClusterManagement : EntityPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override EntityDataSource EntitySource
        {
            get { return this.edsCluster; }
        }

        protected override TextBox EntitySearchTxt
        {
            get { return this.SearchText; }
        }

        protected override Button EntityAddBtn
        {
            get { return this.BtnAdd; }
        }

        protected override Button EntitySearchBtn
        {
            get { return this.Searchbtn; }
        }
        protected override Button EntityClearBtn
        {
            get { return this.Cleanbtn; }
        }

        protected override GridView EntityGrid
        {
            get { return this.gvCluster; }
        }

        protected override DetailsView EntityDetails
        {
            get { return this.dvCluster; }
        }

        protected override void OnEntityDisabling(int entityKey)
        {
            ClusterManagementHelper.SetClusterDisabled(entityKey);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CID, "Cluster disabled. id=" + entityKey + "; name=" + ClusterManagementHelper.getName(entityKey));

        }

        protected override string GetEntityWhereExpression(string keyword)
        {
            return "(it.Name like N'%" + keyword + "%'"
                 + " or it.Description like N'%" + keyword + "%')";
        }

        protected override void OnEntityInserting(EntityDataSourceChangingEventArgs e)
        {
            var dc = e.Context;
            var cluster = e.Entity as Cluster;
            var provinceList = this.Request.Form["provincecheck"];

            ClusterManagementHelper.OnClusterInserting(dc, cluster, provinceList);
        }

        protected override void OnEntityUpdating(EntityDataSourceChangingEventArgs e)
        {
            var dc = e.Context;
            var cluster = e.Entity as Cluster;
            var provinceList = this.Request.Form["provincecheck"];

            ClusterManagementHelper.OnClusterUpdating(dc, cluster, provinceList);
        }



        protected void edsCluster_Inserted(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var cluster = e.Entity as Cluster;
            var provinces = LogInfoHelper.GetProvinceWithCluster(cluster.ClusterID);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CID, "Cluster inserted. id=" + cluster.ClusterID + "; name=" + cluster.Name + "; Comment=" + cluster.Description + "; province=" + provinces);
        }

        protected void edsCluster_Updated(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var cluster = e.Entity as Cluster;
            var provinces = LogInfoHelper.GetProvinceWithCluster(cluster.ClusterID);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CID, "Cluster updated. id=" + cluster.ClusterID + "; name=" + cluster.Name + "; Comment=" + cluster.Description + "; province=" + provinces);
        }


    }
}
